/***************************************************************************************************
*Copyright(C),2017-2020,Sumscope
*FileName	:  FixedScreenMatrixData
*Author	:  Givins.zhu
*Version	:  2.0
*Date		:  2019/09/24
*Desc		:
*History	:
*Email    :  Givins.zhu@sumscope.com
***************************************************************************************************/
#pragma once
#include "../QbBondDefines.h"
#include <bondlib/BondDeal/BondDealTermRange.h>
#include <qbprotocol/include/SSQBModel.h>
#include <QList>

struct BondDealMatrixCellData {
public:
	int m_bondIndex = -1;
	int m_dealCount = 0;
	time_t m_lastUpdate = 0;
};

class S_QBBOND_EXPORT BondDealMatrixData{
public:
	BondDealMatrixData();
	~BondDealMatrixData();

	///债券成交
	void reloadBondData();
	bool updateBondData(QList<xQBPanoramicMarketStreamUnit>& lstData, std::map<int, int>& mapResult);// return true need refresh ui, mapResult<cellIndex, bondIndex>

	int getCellData(int nType, int row, int col);//return bondIndex;
	int getCellType(int cell);
	int getCellRow(int cell);
	int getCellCol(int cell);

	void saveTextAndChartType(int textShowType, int chartShowType);
	int textShowType() const;
	int chartShowType() const;

	void setTextShowType(int v);
	void setChartShowType(int v);

private:
	///债券成交
	void clearBondData();
	int  getCellIndex(int nType, int row, int col);
	bool getBondCellKey(int eType, int bondIndex, bool ytm, std::set<int>& setResult);
	bool getRangeColumn(int eType, int nDays, std::set<int>& setResult);
	void loadRangeConfig();
	int	 getTermExchange(CBondDealTermRange::emBondType eType, QString& strTerm);
private:
	int m_dealType;	//
	std::map<int /*type*10000 + row*100 + col*/, BondDealMatrixCellData> m_mapCell;
	std::set<int> m_setBondInvalid;
 	std::map<int, std::set<int>>  m_mapBondFind;
	std::map<int, std::vector<UINT>> m_mapRange;
// 	std::set<int> m_setResult;
// 	std::set<int> m_setTempResult;
	int     m_textType = 0;
	int     m_chartType = 0;
};
